<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2019/12/21
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="dao.itemDao"  %>
<%@ page import="enity.Items" %>
<%@ page import="java.util.ArrayList" %>
<html>
<head>
    <title>详细商品</title>
</head>
<%
    //获取cookie集合
    Cookie [] cookies=request.getCookies();
    String list="";
    //遍历cookie集合,找到listviewcode
    if(cookies!=null&&cookies.length>0) {
        for (Cookie c : cookies) {
            if (c.getName().equals("listcode")) {
                list = c.getValue();        //获取对应cookie值
            }
        }
    }
    //若cookie值大于1000,则清零
    String [] arr=list.split("-");
    if(arr!=null&&arr.length>1000){
        list="";
    }
    list+=request.getParameter("id")+"-";      //记录一次浏览记录
    Cookie cookie=new Cookie("listcode",list);
    response.addCookie(cookie);                        //刷新listcode
 %>



<body>
<%
     itemDao dao=new itemDao();
     Items items=dao.getItemById(Integer.parseInt(request.getParameter("id")));

  %>
<table align="center" cellspacing="0" >
    <tr>
        <td rowspan="4">
              <img src="image/<%=items.getPicture()%>" width="200" height="200">
           </td>
    </tr>

    <tr>
        <td>
           <B><%=items.getName()%></B>
        </td>
    </tr>

    <tr>
        <td>
           价格: <%=items.getPrice()%>￥
        </td>
    </tr>

    <tr>
        <td>
            产地:<%=items.getCity()%>
        </td>
    </tr>

</table>

<table align="right" width=30% cellspacing="0">
    <tr>
        <td>
            <B>浏览记录</B>
        </td>
    </tr>
    <%
        itemDao b=new itemDao();
        ArrayList<Items> a=b.getViewList(list);

        for(Items i:a){
     %>
     <tr>
         <td>
             <div>
               <a href="details.jsp?id=<%=i.getId()%>" >  <img src="image/<%=i.getPicture()%>" width="200" height="200">  </a><br>
                <%=i.getName()%>
             </div>

         </td>
     </tr>
    <%
        }
    %>

</table>
</body>
</html>
